home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / term / nextfe.trm < prev    next >
Encoding:
Text File  |  1995-06-12  |  11.0 KB  |  390 lines

  1. /* GNUPLOT - nextfe.trm */
  2.  
  3. /* $Id: nextfe.trm,v 1.3 1993/04/14 20:09:47 davis Exp $ */
  4.  
  5. /*
  6.  * Copyright (C) 1990, 1992
  7.  *
  8.  * Permission to use, copy, and distribute this software and its
  9.  * documentation for any purpose with or without fee is hereby granted, 
  10.  * provided that the above copyright notice appear in all copies and 
  11.  * that both that copyright notice and this permission notice appear 
  12.  * in supporting documentation.
  13.  *
  14.  * Permission to modify the software is granted, but not the right to
  15.  * distribute the modified code.  Modifications are to be distributed 
  16.  * as patches to released version.
  17.  *  
  18.  * This software  is provided "as is" without express or implied warranty.
  19.  * 
  20.  * This file is included by ../term.c.
  21.  *
  22.  * This terminal driver supports:
  23.  *     postscript
  24.  *
  25.  * AUTHORS
  26.  *  Russell Lang (modified for the NeXTSTEP Front End by Robert Davis)
  27.  * 
  28.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  29.  *
  30.  * The 'postscript' driver produces landscape output 10" wide and 7" high.  
  31.  * To change font to Times-Roman and font size to 20pts use 
  32.  * 'set term postscript "Times-Roman" 20'.
  33.  * To get a smaller (5" x 3.5") eps output use 'set term post eps'
  34.  * and make only one plot per file.  Font size for eps will be half
  35.  * the specified size.
  36.  */
  37.  
  38.  
  39. /* PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  40. /* Modified by Robert Davis, davis@ecn.purdue.edu, 71302,273@compuserve.com */
  41.  
  42. #import <streams/streams.h>
  43.  
  44. NXStream *EPSStream;
  45. TBOOLEAN nextfe_needsReset;
  46.  
  47. /* 
  48.  * The postscript driver by Russell Lang automatically halves the size 
  49.  * of EPS plots, as if you had done a "set size .5,.5".  This is 
  50.  * handy, since most EPS plots don't need to be page-sized, but it may 
  51.  * come as a suprise for folks not expecting it.  To turn it off, set 
  52.  * nextfe_halve to FALSE.
  53.  */
  54. TBOOLEAN nextfe_halve = TRUE;
  55.  
  56. char nextfe_font[MAX_ID_LEN+1] = "Helvetica" ;    /* name of font */
  57. int nextfe_fontsize = 14;            /* size of font in pts */
  58. TBOOLEAN nextfe_color = FALSE;
  59. TBOOLEAN nextfe_solid = FALSE;
  60.  
  61. int nextfe_path_count=0;            /* count of lines in path */
  62. int nextfe_ang=0;                /* text angle */
  63. enum JUSTIFY nextfe_justify=LEFT;        /* text is flush left */
  64.  
  65. char *NEXTFE_header[] = {
  66. "/M {moveto} bind def\n",
  67. "/L {lineto} bind def\n",
  68. "/R {rmoveto} bind def\n",
  69. "/V {rlineto} bind def\n",
  70. "/vpt2 vpt 2 mul def\n",
  71. "/hpt2 hpt 2 mul def\n",
  72. /* flush left show */
  73. "/Lshow { currentpoint stroke M\n",
  74. "  0 vshift R show } def\n", 
  75. /* flush right show */
  76. "/Rshow { currentpoint stroke M\n",
  77. "  dup stringwidth pop neg vshift R show } def\n", 
  78. /* centred show */
  79. "/Cshow { currentpoint stroke M\n",
  80. "  dup stringwidth pop -2 div vshift R show } def\n", 
  81. /* Dash or Color Line */
  82. "/DL { Color {setrgbcolor Solid {pop []} if 0 setdash }\n",
  83. " {pop pop pop Solid {pop []} if 0 setdash} ifelse } def\n",
  84. /* Border Lines */
  85. "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
  86. /* Axes Lines */
  87. "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
  88. /* Plot Lines */
  89. "/PL { stroke gnulinewidth setlinewidth } def\n",
  90. /* Line Types */
  91. "/LTb { BL [] 0 0 0 DL } def\n", /* border */
  92. "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
  93. "/LT0 { PL [] 0 1 0 DL } def\n",
  94. "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
  95. "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
  96. "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
  97. "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
  98. "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
  99. "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
  100. "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
  101. "/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
  102. "/P { stroke [] 0 setdash\n", /* Point */
  103. "  currentlinewidth 2 div sub M\n",
  104. "  0 currentlinewidth V stroke } def\n",
  105. "/D { stroke [] 0 setdash 2 copy vpt add M\n", /* Diamond */
  106. "  hpt neg vpt neg V hpt vpt neg V\n",
  107. "  hpt vpt V hpt neg vpt V closepath stroke\n",
  108. "  P } def\n",
  109. "/A { stroke [] 0 setdash vpt sub M 0 vpt2 V\n", /* Plus (Add) */
  110. "  currentpoint stroke M\n",
  111. "  hpt neg vpt neg R hpt2 0 V stroke\n",
  112. "  } def\n",
  113. "/B { stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M\n", /* Box */
  114. "  0 vpt2 neg V hpt2 0 V 0 vpt2 V\n",
  115. "  hpt2 neg 0 V closepath stroke\n",
  116. "  P } def\n",
  117. "/C { stroke [] 0 setdash exch hpt sub exch vpt add M\n", /* Cross */
  118. "  hpt2 vpt2 neg V currentpoint stroke M\n",
  119. "  hpt2 neg 0 R hpt2 vpt2 V stroke } def\n",
  120. "/T { stroke [] 0 setdash 2 copy vpt 1.12 mul add M\n", /* Triangle */
  121. "  hpt neg vpt -1.62 mul V\n",
  122. "  hpt 2 mul 0 V\n",
  123. "  hpt neg vpt 1.62 mul V closepath stroke\n",
  124. "  P  } def\n",
  125. "/S { 2 copy A C} def\n", /* Star */
  126. NULL
  127. };
  128.  
  129. #define NEXTFE_XOFF    50    /* page offset in pts */
  130. #define NEXTFE_YOFF    50
  131.  
  132. #define NEXTFE_XMAX 7200
  133. #define NEXTFE_YMAX 5040
  134.  
  135. #define NEXTFE_XLAST (NEXTFE_XMAX - 1)
  136. #define NEXTFE_YLAST (NEXTFE_YMAX - 1)
  137.  
  138. #define NEXTFE_VTIC (NEXTFE_YMAX/80)
  139. #define NEXTFE_HTIC (NEXTFE_YMAX/80)
  140.  
  141. #define NEXTFE_SC (10)                /* scale is 1pt = 10 units */
  142. #define    NEXTFE_LW (0.5*NEXTFE_SC)        /* linewidth = 0.5 pts */
  143.  
  144. #define NEXTFE_VCHAR (14*NEXTFE_SC)    /* default is 14 point characters */
  145. #define NEXTFE_HCHAR (14*NEXTFE_SC*6/10)
  146.  
  147. int NEXTFE_pen_x, NEXTFE_pen_y;
  148. int NEXTFE_taken;
  149. int NEXTFE_linetype_last;
  150. TBOOLEAN NEXTFE_relative_ok;
  151.  
  152. NEXTFE_options()
  153. {
  154.     extern struct value *const_express();
  155.     extern double real();
  156.  
  157. /*    if (!END_OF_COMMAND) {                //
  158.         if (almost_equals(c_token,"s$olid")) {
  159.         nextfe_solid=TRUE;
  160.         c_token++;
  161.         }
  162.         else if (almost_equals(c_token,"d$ashed")) {
  163.         nextfe_solid=FALSE;
  164.         c_token++;
  165.         }
  166.     }
  167. */
  168.     if (!END_OF_COMMAND && isstring(c_token)) {
  169.         quote_str(nextfe_font,c_token);
  170.         c_token++;
  171.     }
  172.  
  173.     if (!END_OF_COMMAND) {
  174.         /* We have font size specified */
  175.         struct value a;
  176.         nextfe_fontsize = (int)real(const_express(&a));
  177.         term_tbl[term].v_char = (unsigned int)(nextfe_fontsize*NEXTFE_SC);
  178.         term_tbl[term].h_char = (unsigned int)(nextfe_fontsize*NEXTFE_SC*6/10);
  179.     }
  180.  
  181. }
  182.  
  183.  
  184. NEXTFE_init()
  185. {
  186. struct termentry *t = &term_tbl[term];
  187. int i;
  188.     nextfe_needsReset = TRUE;
  189.  
  190.     NXPrintf(EPSStream,"%%!PS-Adobe-2.0 EPSF-2.0\n");
  191.     NXPrintf(EPSStream,"%%%%Creator: gnuplot\n");
  192.     NXPrintf(EPSStream,"%%%%DocumentFonts: %s\n", nextfe_font);
  193.     NXPrintf(EPSStream,"%%%%BoundingBox: %d %d ", NEXTFE_XOFF,NEXTFE_YOFF);
  194.  
  195.     /*
  196.      * The following calculates the size of the bounding box.  If 
  197.      * nextfe_halve is TRUE, the actual size of the entire plot, 
  198.      * including fonts, is halved.
  199.      */
  200.     NXPrintf(EPSStream,"%d %d\n", 
  201.     (int)(xsize * (nextfe_halve? 0.5: 1.0) * (NEXTFE_XMAX) / NEXTFE_SC
  202.           + 0.5 + NEXTFE_XOFF), 
  203.     (int)(ysize * (nextfe_halve? 0.5: 1.0) * (NEXTFE_YMAX) / NEXTFE_SC
  204.           + 0.5 + NEXTFE_YOFF));
  205.  
  206.     NXPrintf(EPSStream,"%%%%EndComments\n");
  207.     NXPrintf(EPSStream,"/gnudict 40 dict def\ngnudict begin\n");
  208.     NXPrintf(EPSStream,"/Color %s def\n",nextfe_color ? "true" : "false");
  209.     NXPrintf(EPSStream,"/Solid %s def\n",nextfe_solid ? "true" : "false");
  210.     NXPrintf(EPSStream,"/gnulinewidth %.3f def\n",NEXTFE_LW);
  211.     NXPrintf(EPSStream,"/vshift %d def\n", (int)(t->v_char)/(-3));
  212.     NXPrintf(EPSStream,"/dl {%d mul} def\n",NEXTFE_SC); /* dash length */
  213.     NXPrintf(EPSStream,"/hpt %.1f def\n",NEXTFE_HTIC/2.0);
  214.     NXPrintf(EPSStream,"/vpt %.1f def\n",NEXTFE_VTIC/2.0);
  215.     for ( i=0; NEXTFE_header[i] != NULL; i++)
  216.         NXPrintf(EPSStream,"%s",NEXTFE_header[i]);
  217.     NXPrintf(EPSStream,"end\n");
  218.     NXPrintf(EPSStream,"%%%%EndProlog\n");
  219. }
  220.  
  221.  
  222. NEXTFE_graphics()
  223. {
  224.     struct termentry *t = &term_tbl[term];
  225.     NXPrintf(EPSStream,"gnudict begin\n");
  226.     NXPrintf(EPSStream,"gsave\n");
  227.     NXPrintf(EPSStream,"%d %d translate\n",NEXTFE_XOFF,NEXTFE_YOFF);
  228.  
  229.     /*
  230.      * The following scales the plot.  It halves the actual size
  231.      * of the plot if nextfe_halve is TRUE.
  232.      */    
  233.     NXPrintf(EPSStream,"%.3f %.3f scale\n", (nextfe_halve? 0.5: 1.0)
  234.          / NEXTFE_SC, (nextfe_halve? 0.5: 1.0) / NEXTFE_SC);
  235.     NXPrintf(EPSStream,"0 setgray\n");
  236.     NXPrintf(EPSStream,"/%s findfont %d ",nextfe_font, (t->v_char) );
  237.     NXPrintf(EPSStream,"scalefont setfont\n");
  238.     NXPrintf(EPSStream,"newpath\n");
  239.     nextfe_path_count = 0;
  240.  
  241.     NEXTFE_relative_ok = FALSE;
  242.     NEXTFE_pen_x = NEXTFE_pen_y = -4000;
  243.     NEXTFE_taken = 0;
  244.     NEXTFE_linetype_last = -1;
  245. }
  246.  
  247.  
  248. NEXTFE_text()
  249. {
  250.     nextfe_path_count = 0;
  251.     NXPrintf(EPSStream,"stroke\ngrestore\nend\nshowpage\n");
  252. }
  253.  
  254.  
  255. NEXTFE_reset()
  256. {
  257.     if (nextfe_needsReset) {
  258.         NXPrintf(EPSStream,"%%%%Trailer\n");
  259.         NXFlush(EPSStream);
  260.         nextfe_needsReset = FALSE;
  261.     }
  262. }
  263.  
  264.  
  265. NEXTFE_linetype(linetype)
  266. int linetype;
  267. {
  268.     char *line = "ba012345678"; 
  269.  
  270.     linetype = (linetype % 9) + 2;
  271.     NEXTFE_relative_ok = FALSE;
  272.     if (NEXTFE_linetype_last == linetype) return (0);
  273.     NEXTFE_linetype_last = linetype;
  274.     NXPrintf(EPSStream,"LT%c\n", line[linetype]);
  275.     nextfe_path_count = 0;
  276. }
  277.  
  278.  
  279. NEXTFE_move(x,y)
  280. unsigned int x,y;
  281. {
  282.     int dx, dy;
  283.     char abso[20],rel[20];
  284.     dx = x - NEXTFE_pen_x;
  285.     dy = y - NEXTFE_pen_y;
  286.     /* can't cancel all null moves--need a move after stroking */
  287.     if (dx==0 && dy==0 && NEXTFE_relative_ok)
  288.     return;
  289.     sprintf(abso, "%d %d M\n", x, y);
  290.     sprintf(rel, "%d %d R\n", dx, dy);
  291.     if (strlen(rel) < strlen(abso) && NEXTFE_relative_ok){
  292.     NXPrintf(EPSStream, "%s",rel);
  293.     NEXTFE_taken++;
  294.     }else
  295.     NXPrintf(EPSStream, "%s",abso);
  296.     NEXTFE_relative_ok = TRUE;
  297.     nextfe_path_count += 1;
  298.     NEXTFE_pen_x = x;
  299.     NEXTFE_pen_y = y;
  300. }
  301.  
  302.  
  303. NEXTFE_vector(x,y)
  304. unsigned int x,y;
  305. {
  306.     int dx, dy;
  307.     char abso[20],rel[20];
  308.     dx = x - NEXTFE_pen_x;
  309.     dy = y - NEXTFE_pen_y;
  310.     if (dx==0 && dy==0) return;
  311.     sprintf(abso, "%d %d L\n", x, y);
  312.     sprintf(rel, "%d %d V\n", dx, dy);
  313.     if (strlen(rel) < strlen(abso) && NEXTFE_relative_ok){
  314.     NXPrintf (EPSStream, "%s", rel);
  315.     NEXTFE_taken++;
  316.     }else
  317.     NXPrintf (EPSStream, "%s", abso);
  318.     NEXTFE_relative_ok = TRUE;
  319.     nextfe_path_count += 1;
  320.     NEXTFE_pen_x = x;
  321.     NEXTFE_pen_y = y;
  322.     if (nextfe_path_count >= 400) {
  323.     NXPrintf (EPSStream, "currentpoint stroke M\n");
  324.     nextfe_path_count = 0;
  325.     }
  326. }
  327.  
  328.  
  329. NEXTFE_put_text(x,y,str)
  330. unsigned int x, y;
  331. char *str;
  332. {
  333.     char ch;
  334.     if (!strlen (str)) return;
  335.     NEXTFE_move(x,y);
  336.     if (nextfe_ang != 0)
  337.     NXPrintf(EPSStream,"currentpoint gsave translate %d rotate 0 0 M\n"
  338.             ,nextfe_ang*90);
  339.     NXPutc(EPSStream, '(');
  340.     ch = *str++;
  341.     while(ch!='\0') {
  342.     if ( (ch=='(') || (ch==')') || (ch=='\\') )
  343.         NXPutc(EPSStream,'\\');
  344.     NXPutc(EPSStream,ch);
  345.     ch = *str++;
  346.     }
  347.     switch(nextfe_justify) {
  348.     case LEFT : NXPrintf(EPSStream,") Lshow\n");
  349.     break;
  350.     case CENTRE : NXPrintf(EPSStream,") Cshow\n");
  351.     break;
  352.     case RIGHT : NXPrintf(EPSStream,") Rshow\n");
  353.     break;
  354.     }
  355.     if (nextfe_ang != 0)
  356.     NXPrintf(EPSStream,"grestore\n");
  357.     nextfe_path_count = 0;
  358.     NEXTFE_relative_ok = FALSE;
  359. }
  360.  
  361. int NEXTFE_text_angle(ang)
  362. int ang;
  363. {
  364.     nextfe_ang=ang;
  365.     return TRUE;
  366. }
  367.  
  368. int NEXTFE_justify_text(mode)
  369. enum JUSTIFY mode;
  370. {
  371.     nextfe_justify=mode;
  372.     return TRUE;
  373. }
  374.  
  375. /* postscript point routines */
  376. NEXTFE_point(x,y,number)
  377. int x,y;
  378. int number;
  379. {
  380.     char *point = "PDABCTS";
  381.     number %= POINT_TYPES;
  382.     if (number < -1)
  383.     number = -1;        /* negative types are all 'dot' */
  384.     NXPrintf(EPSStream,"%d %d %c\n", x, y, point[number+1]);
  385.  
  386.     NEXTFE_relative_ok = 0;
  387.     nextfe_path_count = 0;
  388.     NEXTFE_linetype_last = -1;    /* force next linetype change */
  389. }
  390.